package mysql

import (
	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Account   string `gorm:"type:varchar(30);not null;comment:'账号'"`
	Password  string `gorm:"type:varchar(32);not null;comment:‘密码"`
	Username  string `gorm:"type:varchar(30);comment:'姓名'"`
	Marriage  string `gorm:"type:enum('是','否');comment:'是否婚配'"`
	CardImage string `gorm:"type:varchar(500);comment:'身份证上传'"`
	Card      string `gorm:"type:char(18);comment:'证件号码'"`
	Sex       string `gorm:"type:enum('男','女');comment:'性别'"`
	Birth     string `gorm:"type:datetime;comment:'出生日期'"`
	Phone     string `gorm:"type:char(11);comment:'手机号'"`
}

func (u *User) FindUserByUsername(db *gorm.DB, account string) error {
	return db.Debug().Where("account=?", account).First(u).Error
}

func (u *User) FindUserByUserId(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(u).Error
}

func (u *User) UserShow(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Find(u).Error
}

func (u *User) UpdateUser(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}
